<?php


namespace app\service;

class Y
{
    /**
     * 响应正确结果
     * @param array $data
     * @param string $msg
     * @param string $url
     * @param int $code
     * @return \think\response\Json
     */
    public static function success($data = [], $msg = 'success', $url = '', $code = 0): \think\response\Json
    {
        return json([
            'code'  => $code,
            'data'  => $data,
            'msg'   => $msg,
            'url'   => $url
        ]);
    }

    /**
     * 响应错误结果
     * @param string $msg
     * @param array $data
     * @param int $code
     * @return \think\response\Json
     */
    public static function error($msg = 'error', $data = [], $code = 1): \think\response\Json
    {
        return json([
            'code'  => $code,
            'data'  => $data,
            'msg'   => $msg
        ]);
    }

    /**
     * 响应正确结果
     * @param array $data
     * @param int $count
     * @param string $msg
     * @param array $s
     * @return \think\response\Json
     */
    public static function table($data = [], $count = 0, $msg = 'success', $s = []): \think\response\Json
    {
        return json([
            'code'  => 0,
            'data'  => $data,
            'count' => $count,
            'msg'   => $msg,
            's'     => $s
        ]);
    }
}